<?php

set_time_limit(0);

 $pdo = new PDO("mysql:host=localhost;dbname=hospital","root","tailiyan88"); 
 
$json_string = file_get_contents("a.json");
    
$obj=json_decode($json_string,true);
if (!is_array($obj)) die('no successful');

	foreach($obj as $v){
		$province=$v['label'];
		$key=$v['key'];
		$city="";
		$area="";
		echo $key;
		if(!empty($v["children"])&& is_array($v["children"]))
		{
			foreach($v["children"] as $c)
			{
				$city=$c['label'];
				$key=$c['key'];
				if(!empty($c["children"])&& is_array($c["children"]))
		         {
					 /*foreach($c["children"] as $s)
						{
							$areat=$s['label'];
							$keyt=$s['key'];
							
							$sql="SELECT hospital.danwei,areas.lable,areas.`key` FROM hospital INNER JOIN areas ON hospital.`key` = areas.`key` where hospital.`key`='$keyt'";
							echo "1".$sql."<br>";
							 try{
							    $result=$pdo->query($sql);
								foreach($result as $rowt){
								 $pdo->exec("insert into danweiku(`province`,`city`,`area`,`danwei`) values('$province','$city','$areat','".$rowt['danwei']."')");
								} 
							   }
							   catch (PDOException $e)
							 {
							
								 echo $sql . "<br>" . $e->getMessage();
							 }
							
						}*/
				 }else{
					
					/* $sql="SELECT hospital.danwei,areas.lable,areas.`key` FROM hospital INNER JOIN areas ON hospital.`key` = areas.`key` where hospital.`key`='$key'";
	               	echo "2".$sql."<br>";		
					try{
					    $result=$pdo->query($sql);
						foreach($result as $row){
						 $pdo->exec("insert into danweiku(`province`,`city`,`area`,`danwei`) values('$province','$city','','".$row['danwei']."')");
						}
					 }
					 catch (PDOException $e)
					 {
					
						 echo $sql . "<br>" . $e->getMessage();
					 }*/
					
				 }
			}
		 
		}else{
			/*$result=$pdo->query("SELECT hospital.danwei,areas.lable,areas.`key` FROM hospital INNER JOIN areas ON hospital.`key` = areas.`key` where hospital.`key`='$key'");
			
			foreach($result as $row){
			$pdo->exec("insert into danweiku(`province`,`city`,`area`,`danwei`) values('$province','','','".$row['danwei']."')");
			}*/
		}
			
	}
	
	